<!DOCTYPE html>
<html>
	<head>
		<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
		<meta content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport" />
		<meta content="telephone=no" name="format-detection" />
		<meta content="address=no" name="format-detection" />
		<meta name="apple-mobile-web-app-capable" content="no" />
		<link rel="apple-touch-icon-precomposed" href="http://img0.zz91.com/zz91/images/logo.png" />
		<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-precomposed" />
		<meta name="apple-touch-fullscreen" content="YES">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="shortcut icon" href="http://img0.zz91.com/front/favicon.ico" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="/layui/css/layui.css"/>	
		<script type="text/javascript" src="/layui/layui.js"></script>
		<script src="/js/jquery.js" charset="utf-8"></script>
		<script src="/js/comm.js" charset="utf-8"></script>
		<style>
			.mainbox{
				margin: 10px;
			}
		</style>
		<script>
			function selectoption(id,value){
				$("#"+id).val(value)
			}
		</script>
	</head>
	<body>
		<div class="mainbox">
			<form class="layui-form" action="" method="post">
				<div class="layui-form-item">
				    <label class="layui-form-label"><span style="color: red;">*</span>车牌号</label>
				    <div class="layui-input-block">
				      	<input type="text" name="licence" lay-verify="required" autocomplete="off" value="{{result.licence}}" placeholder="请输入车牌号" class="layui-input">
				    </div>
			  	</div>
			  	<div class="layui-form-item">
				    <label class="layui-form-label"><span style="color: red;">*</span>分站（分公司）</label>
				    <div class="layui-input-block">
				      	<select name="company_id" id="company_id" lay-verify="required">
				      		<option value="">请选择...</option>
				      		{%for list in company_list%}
							<option value="{{list.id}}">{{list.name}}</option>
							{%endfor%}
				      	</select>
				      	<script>selectoption("company_id","{{result.company_id}}")</script>
				    </div>
			  	</div>
			  	
			  	<div class="layui-form-item">
			    	<label class="layui-form-label">皮重</label>
			    	<div class="layui-input-block">
			      		<input type="number" name="tare" lay-verify="required" value="{{result.tare}}" placeholder="请输入皮重" autocomplete="off" class="layui-input">
			    	</div>
			  	</div>
			  	
			  
				 <div class="layui-form-item">
				    <label class="layui-form-label">供应商</label>
				    <div class="layui-input-inline">
				        <input name="suppliersname" id="suppliersname" value="{{result.suppliersname}}" autocomplete="off" class="layui-input">
				    </div>
				    <input type="hidden" name="suppliers_selfid" id="suppliers_selfid" value="{{result.suppliers_selfid}}"/>
				    <button type="button" class="layui-btn layui-btn-normal selectsupplier">选择供应商</button>
				</div>
			  	
			  	<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">备注</label>
				    <div class="layui-input-block">
				      <textarea placeholder="请输入内容" class="layui-textarea" name="bz">{{result.bz}}</textarea>
				    </div>
				</div>
				
				<div class="layui-form-item layui-col">
					<div class="layui-input-block">
					    <button class="layui-btn layui-btn-normal layui-col-xs2" lay-submit="" lay-filter="demo1">保存</button>
					    <button type="reset" class="layui-btn layui-btn-primary layui-col-xs2">清除</button>
					</div>
				</div>
				<input type="hidden" name="id" id="id" value="{{id}}" />
			</form>
		</div>
		<script id="barcaozuo" type="text/html">
		  <a class="layui-btn layui-btn-mini" lay-event="select">选择</a>
		</script>
		<div class="supplierlist" style="display: none;">
			<div class="demoTable">
			  	<div class="layui-inline">
			    	<input class="layui-input" name="iccode" id="iccode" autocomplete="off" placeholder="编号">
			  	</div>
			  	<div class="layui-inline">
			    	<input class="layui-input" name="name" id="name" autocomplete="off" placeholder="名称">
			  	</div>
			  	<button class="layui-btn layui-btn-normal" data-type="reload">查询</button>
			</div>
			<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
		</div>
	</body>
		
	<script>
		layui.use(['form', 'layedit', 'laydate','table'], function() {
			var form = layui.form,
				layer = layui.layer,
				layedit = layui.layedit
			var table = layui.table;
		  var $ = layui.$;
			//方法级渲染
		  function tablerender(){table.render({
		    elem: '#LAY_table_user'
		    ,url: 'supplier_data.html?iccode='+$("#iccode").val()+'&name='+$("#name").val()
		    ,cols: [[
		      {field:'id', title: '序号', width:80,fixed:true, edit: 'text'}
		      ,{field:'name', title: '供应商名称', width:130, edit: 'text'}
		      ,{field:'contact', title: '联系人', width:100, edit: 'text'}
		      ,{field:'mobile', title: '手机号码', width:120, edit: 'text'}
		      ,{field:'caozuo', title: '操作', width:200,toolbar:'#barcaozuo'}
		    ]]
		    ,id: 'testReload'
		    ,page: true
		    ,limit: 10
		    ,limits:[]
		    ,height: 500
		  })};
		  tablerender();
		  //监听工具条
		  table.on('tool(user)', function(obj){
		    var data = obj.data;
		    if(obj.event === 'select'){
		        $("#suppliersname").val(data.name)
		        $("#suppliers_selfid").val(data.selfid)
		        layer.closeAll();
		    }
		   
		  });

		  $('.demoTable .layui-btn-normal').on('click', function(){
		    tablerender();
		  });
		  //监听提交
			form.on('submit(demo1)', function(data) {
				var datalist=data.field;
				//alert(JSON.stringify(datalist))
				layer.load(2)
				crmajax("post","/car_save.html",datalist,function(ret){
					//alert(JSON.stringify(ret))
					if (ret) {
						if (ret.err == 'false') {
							layer.msg("添加成功！");
							window.location='/car_list.html?backurl={{backurl}}'
						} else {
							layer.msg(ret.errkey)
						}
					} else {
						
					};
					layer.closeAll('loading');
				},function(err){
					//alert(JSON.stringify(err))
					layer.closeAll('loading');
				});
				return false;
			});

		});
		$(function(){
			$(".selectsupplier").on("click", function() {
				layer.open({
					type: 1,
					title: '选择供应商',
					shadeClose: true,
					shade: 0.3,
					scrollbar: false,
					area: ['700px', '600px'],
					content: $('.supplierlist') //iframe的url
				}); 
			});
		})
	</script>
</html>
